package com.hgyc.mom.mes.event;

import com.hgyc.mom.base.entity.Material;
import com.hgyc.mom.base.service.MaterialService;
import com.hgyc.mom.common.util.StringUtils;
import com.hgyc.mom.mes.entity.SopAttachment;
import com.hgyc.mom.mes.entity.SopDocument;
import com.hgyc.mom.mes.entity.SopSendRecord;
import com.hgyc.mom.mes.entity.SopTerminal;
import com.hgyc.mom.mes.service.SopAttachmentService;
import com.hgyc.mom.mes.service.SopDocumentManageService;
import com.hgyc.mom.mes.service.SopDocumentService;
import com.hgyc.mom.mes.service.SopTerminalService;
import com.hgyc.mom.mes.vo.LineInProductVO;
import com.hgyc.mom.mes.vo.SopDocumentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 转产事件监听
 * @author fwj
 * @since 2025/5/9
 */
@Slf4j
@Component
public class ProductChangeListener {

    @Autowired
    private MaterialService materialService;

    @Autowired
    private SopDocumentService sopDocumentService;

    @Autowired
    private SopTerminalService sopTerminalService;
    @Autowired
    private SopDocumentManageService sopDocumentManageService;

    @Async
    @EventListener
    public void handleEvent(ProductChangeEvent event) {
        LineInProductVO lineInProductVO = event.getLineInProductVO();

        log.info("产线: [{}] 转产，产品ID: [{}]", lineInProductVO.getLineId(), lineInProductVO.getMaterialId());

        Material product = materialService.getById(lineInProductVO.getMaterialId());
        if (product == null) {
            return;
        }

        // TODO 更新SOP文档

    }

}
